$(window).load(function(){
	//페이지 로딩시 실행되야 하는 것들
	position_script();
	last_line_script();

	$(".disBtn").toggle(function() {
		$(this).find("img").animate({left: '-65px'},300 , "easeOutExpo");
		$(this).find("img").attr("alt","off");
		$(this).next("#displays").val("N")
	}, function() {
		$(this).find("img").animate({left: '0px'},300 , "easeOutExpo");
		$(this).find("img").attr("alt","on");
		$(this).next("#displays").val("Y")
	});
});

function scrollTopAc(){
	var aTag = $(".topEnd");
	$('html, body').animate({scrollTop: aTag.offset().top-50},'slow');
};

function openLy(cName){
	$("html,body").css("overflow","hidden");
	$("#layerBg").show();
	$(".layer_"+cName).show();
};
function closeLy(){
	$("html,body").css("overflow","auto");
	$("#layerBg").hide();
	$("#layerArea").hide();
};
// 마지막 라인 지우기 위한 Script
function last_line_script(){
	$(".board_list").each(function(index){
		$(this).find("tr:last").addClass("borderNone");
	});
	$(".board_view").each(function(index){
		$(this).find("tr:last").addClass("borderNone");
	});
	$(".board_write").each(function(index){
		$(this).find("tr:last").addClass("borderNone");
	});

	$(".box_type02").each(function(index){
		$(this).find("tr").each(function(index){
			$(this).find("th").eq(0).css("border-left","none");
		});

		if($(this).height() >= "219"){
			$(this).find("table").css("border-bottom","none");
		}else{
			$(this).find("table").css("border-bottom","1px solid #cdcdcd");
		}
	});
};
// 자리배치를 위한 Script
function position_script(){
	$(".botton_box").each(function(index){
		var botton_h = $(this).find("li").height();
		var botton_c = $(this).find(".center").width() / 2;

		$(this).css("height", botton_h+"px");
		$(this).find(".center").css("margin-left", -botton_c+"px");
	});
};

// Select Box Script
jQuery(function($){
	// Common
	var select_root = $('div.select');
	var select_value = $('.myValue');
	var select_a = $('div.select>ul>li>a');
	var select_input = $('div.select>ul>li>input[type=radio]');
	var select_label = $('div.select>ul>li>label');

	// Radio Default Value
	$('div.myValue').each(function(){
		var default_value = $(this).next('.iList').find('input[checked]').next('label').text();
		$(this).append(default_value);
	});

	// Line
	select_value.bind('focusin',function(){$(this).addClass('outLine');});
	select_value.bind('focusout',function(){$(this).removeClass('outLine');});
	select_input.bind('focusin',function(){$(this).parents('div.select').children('div.myValue').addClass('outLine');});
	select_input.bind('focusout',function(){$(this).parents('div.select').children('div.myValue').removeClass('outLine');});

	// Show
	function show_option(){
		$(this).parents('div.select:first').toggleClass('open');
	}

	// Hover
	function i_hover(){
		$(this).parents('ul:first').children('li').removeClass('hover');
		$(this).parents('li:first').toggleClass('hover');
	}

	// Hide
	function hide_option(){
		var t = $(this);
		setTimeout(function(){
			t.parents('div.select:first').removeClass('open');
		}, 1);
	}

	// Set Input
	function set_label(){
		var v = $(this).next('label').text();
		$(this).parents('ul:first').prev('.myValue').text('').append(v);
		$(this).parents('ul:first').prev('.myValue').addClass('selected');
	}

	// Set Anchor
	function set_anchor(){
		var v = $(this).text();
		$(this).parents('ul:first').prev('.myValue').text('').append(v);
		$(this).parents('ul:first').prev('.myValue').addClass('selected');
	}

	// Anchor Focus Out
	$('*:not("div.select a")').focus(function(){
		$('.aList').parent('.select').removeClass('open');
	});

	select_value.click(show_option);
	select_root.find('ul').css('position','absolute');
	select_root.removeClass('open');
	select_root.mouseleave(function(){$(this).removeClass('open');});
	select_a.click(set_anchor).click(hide_option).focus(i_hover).hover(i_hover);
	select_input.change(set_label).focus(set_label);
	select_label.hover(i_hover).click(hide_option);

	// Form Reset
	$('input[type="reset"], button[type="reset"]').click(function(){
		$(this).parents('form:first').find('.myValue').each(function(){
			var origin = $(this).next('ul:first').find('li:first label').text();
			$(this).text(origin).removeClass('selected');
		});
	});
});

